//
//  WmcRetainAlert.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/5/14.
//

import UIKit

// MARK: - [WmcRetainAlertView]

class WmcRetainAlertView: WmcBaseView {
    lazy var titleLabel: UILabel = {
        let label = UILabel.YP.Create(text: "确定放弃拍照吗？",
                                      font: 18.yp.uiFont(weight: .medium),
                                      color: UIColor.wmc_grayH2_323233,
                                      alignment: .center)
        return label
    }()

    lazy var disTitleLabel: UILabel = {
        let label = UILabel.YP.Create(text: "完成拍照留证，即可领取：",
                                      font: 15.wmc_font,
                                      color: UIColor.wmc_grayH8_8A8A99,
                                      alignment: .center)
        return label
    }()

    lazy var integralImageView: UIImageView = {
        let imageView = UIImageView(image: "business_integral".wmc_image)
        imageView.contentMode = .scaleAspectFit
        imageView.yp.makeAnimation { make in
            make.basicAnimation(.transform_scale) { [weak self] make in
                guard let weakSelf = self else { return }
                make.set(duration:Wmc_animationDuration)
                    .set(fromValue:1)
                    .set(toValue:0.9)
                    .set(autoreverses:true)
                    .set(removedOnCompletion:false)
                    .setRepeat()
            }
        }

        return imageView
    }()

    lazy var integralLabel: UILabel = {
        let label = UILabel.YP.Create(text: "1个正式积分",
                                      font: 17.yp.uiFont(weight: .bold),
                                      color: UIColor.wmc_yellow_FFC400,
                                      alignment: .center)
        return label
    }()

    lazy var lawyerVideoBtn: WmcLawyerVideoBtn = {
        let btn = WmcLawyerVideoBtn.Create()
        return btn
    }()

    lazy var leaveBtn: UIButton = {
        let btn = UIButton()
        btn.layer.cornerRadius = 4
        btn.layer.masksToBounds = true
        btn.layer.borderColor = UIColor.wmc_grayH14_CCCCCC.cgColor
        btn.layer.borderWidth = 1
        btn.setTitle("狠心离开", for: .normal)
        btn.setTitleColor(.wmc_grayH2_323233, for: .normal)
        btn.titleLabel?.font = 16.wmc_font
        return btn
    }()

    lazy var continueBtn: UIButton = {
        let btn = UIButton.Wmc_themeColorBtn(color: .wmc_mainTheme, title: "继续拍照")
        return btn
    }()

    override func makeUI() {
        layer.cornerRadius = 8
        layer.shadowColor = UIColor.black.cgColor
        layer.shadowOpacity = 0.2
        layer.shadowRadius = 8
        layer.shadowOffset = .zero

        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(Wmc_standardEdge.top + 8)
            make.height.equalTo(22)
        }

        addSubview(disTitleLabel)
        disTitleLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(titleLabel.snp.bottom).offset(4)
            make.height.equalTo(22)
        }

        addSubview(integralImageView)
        integralImageView.snp.makeConstraints { make in
            make.size.equalTo(36)
            make.top.equalTo(disTitleLabel.snp.bottom).offset(12)
            make.centerX.equalToSuperview()
        }

        addSubview(integralLabel)
        integralLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(integralImageView.snp.bottom).offset(12)
            make.height.equalTo(20)
        }

        addSubview(lawyerVideoBtn)
        lawyerVideoBtn.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(integralLabel.snp.bottom).offset(16)
            make.height.equalTo(40)
        }

        addSubview(leaveBtn)
        leaveBtn.snp.makeConstraints { make in
            make.bottom.equalTo(-Wmc_standardEdge.bottom)
            make.left.equalTo(Wmc_standardEdge.left)
            make.right.equalTo(self.snp.centerX).offset(-5)
            make.height.equalTo(44)
        }

        addSubview(continueBtn)
        continueBtn.snp.makeConstraints { make in
            make.bottom.equalTo(-Wmc_standardEdge.bottom)
            make.right.equalTo(-Wmc_standardEdge.right)
            make.left.equalTo(self.snp.centerX).offset(5)
            make.height.equalTo(44)
        }
    }
}

// MARK: - WmcAlertViewProtocol

extension WmcRetainAlertView: WmcAlertViewProtocol {
    /// 显示
    func show() {
        var config = WmcPresentVC.Config(style: .alert(), contentView: self, contentLayoutBlock: { make in
            make.center.equalToSuperview()
            make.left.equalTo(32)
            make.right.equalTo(-32)
            make.height.equalTo(280)
        })
        config.isTouchMaskDismiss = false
        show(config: config)
    }
}
